'use strict';

const BaseController = require('../base');

class BannerController extends BaseController {
  static get serviceName() {
    return 'business.config';
  }
  formatOrder() {
    return [
      ['sort', 'ASC'],
      ['create_time', 'DESC'],
    ]
  }
  // 根据key获取配置
  async getByKey() {
    const { ctx } = this;
    const { key } = ctx.params;

    try {
      const result = await this.service.findByKey(key);
      if (!result) {
        this.ctx.error('配置不存在');
        return;
      }
      this.ctx.success(result);
    } catch (error) {
      this.ctx.error(error.message);
    }
  }
}

module.exports = BannerController;
